namespace IMPlant.Core.Web.Control
{
    using IMPlant.Core.DataInput.Excel;
    using System;
    using System.Data;
    using System.IO;
    using System.Web;
    using System.Web.UI.WebControls;
    public class AnalyzeUpLoad : FileUpload
    {
        public DataSet AnalyzeExcelToDS()
        {
            if (!base.HasFile)
            {
                throw new Exception("1:没有选择文件");
            }
            int num = (base.PostedFile != null) ? base.PostedFile.ContentLength : 0;
            if (num > 0x1e00000)
            {
                throw new Exception("2:所选文件操过30M");
            }
            if (string.IsNullOrEmpty(base.FileName))
            {
                string[] strArray = base.FileName.Split(new char[] { '.' });
                if ((strArray.Length <= 1) || (!strArray[1].ToUpper().Equals("XLS") && !strArray[1].ToUpper().Equals("XLSX")))
                {
                    throw new Exception("3:请确保文件格式是Excel");
                }
            }
            string filePath = this.GetFilePath();
            base.SaveAs(filePath);
            return ExcelReader.GetExcelDataHigh(filePath);
        }

        private string GetFileName()
        {
            return (DateTime.Now.Ticks.ToString() + ".xls");
        }

        private string GetFilePath()
        {
            string path = HttpContext.Current.Server.MapPath("~/UpLoad/ExcelAnalyze/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return (path + this.GetFileName());
        }
    }
}

